
//
//
//package edu.ieslaferreria.creditsintesis.builders;
//
///**
// *Clase que contiene el juego capaz de entrar en el jpanel.
// esta es la clsase original.
// * @author Administrador
// */
//
//
//
//
//import com.jme.input.thirdperson.ThirdPersonMouseLook;
//import com.jme.input.InputHandler;
//import edu.ieslaferreria.creditsintesi.models.Model;
//import edu.ieslaferreria.creditsintesis.controllers.ExternalWorldController;
//import edu.ieslaferreria.creditsintesis.controllers.UserActionController;
//import edu.ieslaferreria.creditsintesis.controllers.WorldController;
//import edu.ieslaferreria.creditsintesis.logicgame.ActionStates;
//import edu.ieslaferreria.creditsintesis.logicgame.ActionStatesHash1;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.BackAction;
//import edu.ieslaferreria.creditsintesis.controllers.CollisionController;
//import edu.ieslaferreria.creditsintesis.controllers.InteractionController;
//import edu.ieslaferreria.creditsintesis.logicgame.ObjectWithStates;
//import edu.ieslaferreria.creditsintesis.logicgame.Player;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.ForwardAction;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.RotateLeftAction;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.RotateRightAction;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.StateChangedEvent;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.StateListener;
//import edu.ieslaferreria.creditsintesis.logicgame.actions.TimeActionEvent;
//import java.util.HashMap;
//
//
//
//import com.jme.bounding.BoundingBox;
//import com.jme.input.ChaseCamera;
//import com.jme.input.ThirdPersonHandler;
//import com.jme.light.DirectionalLight;
//import com.jme.math.FastMath;
//import com.jme.math.Vector3f;
//import com.jme.renderer.ColorRGBA;
//import com.jme.renderer.Renderer;
//import com.jme.scene.Node;
//import com.jme.scene.shape.Box;
//import com.jme.scene.state.CullState;
//import com.jme.system.canvas.SimpleCanvasImpl;
//import com.jme.scene.state.LightState;
//import com.jme.system.GameSettings;
//import com.jmex.terrain.TerrainPage;
//
//
//public class ControlImplementorWorld extends SimpleCanvasImpl {
//
//        private UserActionController userActionController;
//        private ActionStates actionStates = new ActionStatesHash1();
//        private WorldController worldController;
//        private InteractionController interactionController;
//        private CollisionController collisionController;
//        private Player player;
//        private ChaseCamera chaser;
//        private TerrainManager terrainManager = null;
//        private TerrainPage terrain;
//        private Vector3f camPos = new Vector3f();
//        private Sky sky;
//        private ObjectWithStates fixedBox;
//        private ObjectWithStates fixedBox2;
//     public long startTime;
//    private GameSettings settings;
//    //private LightState lightState;
//    private InputHandler input;
//
//
//     public ControlImplementorWorld(int width, int height) {
//        super(width, height);
//    }
//
//
//
//    public void simpleSetup() {
//        setupCharacter();
//        setupTerrain();
//        setupChaseCamera();
//        setupInput();
//
//        startTime = System.currentTimeMillis() + 5000;
//    }
//
//    public void simpleUpdate() {
//
//
//             float interpolation=timer.getTimePerFrame();
//
//            camPos.x = cam.getLocation().x;
//            camPos.y = terrain.getHeight(cam.getLocation()) + 10;
//            camPos.z = cam.getLocation().z;
//            cam.setLocation(camPos);
//            sky.update();
//
//            //update the chase camera to handle the player moving around.
//            chaser.update(interpolation);
//            interactionController.update(interpolation);
// this.doRender();
//        }
//
//
//
////        page.getSurfaceNormal(m_character.getLocalTranslation(), normal);
////        if (normal != null)
////            m_character.rotateUpTo(normal);
//
//
//    private void setupCharacter() {
//         Node n = Model.loadModel("model/zack.obj");
//	n.setLocalScale(.01f);
//	n.setModelBound(new BoundingBox(new Vector3f(), 0.35f, 0.25f, 0.5f));
//        n.updateModelBound();
//
//        Box b = new Box("box", new Vector3f(), 0.35f,0.25f,0.5f);
//        b.setModelBound(new BoundingBox());
//        b.updateModelBound();
//
//        player = new Player(new PlayerStateMachine(), "Player Node",0);
//        player.setLocalTranslation(new Vector3f(95,0, 125));
//        rootNode.attachChild(player);
//        player.attachChild(b);
//        player.attachChild(n);
//        player.updateWorldBound();
//
//        player.setLinealVelocity(70f);
//        player.setRotationVelocity(5f);
//        player.setAction(PlayerStateMachine.ST_MOVING_FORWARD, new ForwardAction(player));
//        player.setAction(PlayerStateMachine.ST_SPINING_LEFT, new RotateLeftAction(player));
//        player.setAction(PlayerStateMachine.ST_SPINING_RIGHT, new RotateRightAction(player));
//        player.setAction(PlayerStateMachine.ST_MOVING_BACK, new BackAction(player));
//
//        player.addListener(PlayerStateMachine.ST_MOVING_FORWARD, new StateListener() {
//            public void onChangeState(StateChangedEvent evt) {
//                player.setPrePosition();
//                player.getAction(PlayerStateMachine.ST_MOVING_FORWARD)
//                            .performAction(new TimeActionEvent(timer.getTimePerFrame()));
//                player.updateGeometricState(timer.getTimePerFrame(), false);
//
//                player.processTransition(PlayerStateMachine.TR_MOVED);
//            }
//        });
//
//         player.addListener(PlayerStateMachine.ST_MOVING_BACK, new StateListener() {
//            public void onChangeState(StateChangedEvent evt) {
//                player.setPrePosition();
//                player.getAction(PlayerStateMachine.ST_MOVING_BACK)
//                            .performAction(new TimeActionEvent(timer.getTimePerFrame()));
//                player.updateGeometricState(timer.getTimePerFrame(), false);
//                player.processTransition(PlayerStateMachine.TR_MOVED);
//            }
//        });
//
//
//        player.addListener(PlayerStateMachine.ST_SPINING_LEFT, new StateListener() {
//            public void onChangeState(StateChangedEvent evt) {
//                player.setPrePosition();
//                player.getAction(PlayerStateMachine.ST_SPINING_LEFT)
//                            .performAction(new TimeActionEvent(timer.getTimePerFrame()));
//                player.updateGeometricState(timer.getTimePerFrame(), false);
//                player.processTransition(PlayerStateMachine.TR_SPINNED);
//            }
//        });
//
//        player.addListener(PlayerStateMachine.ST_SPINING_RIGHT, new StateListener() {
//            public void onChangeState(StateChangedEvent evt) {
//                player.setPrePosition();
//                player.getAction(PlayerStateMachine.ST_SPINING_RIGHT)
//                            .performAction(new TimeActionEvent(timer.getTimePerFrame()));
//                player.updateGeometricState(timer.getTimePerFrame(), false);
//                player.processTransition(PlayerStateMachine.TR_SPINNED);
//            }
//        });
//
//        actionStates.addObject(player);
//    }
//
//
// private void setupTerrain() {
// rootNode.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
//
//        renderer.setBackgroundColor(
//                new ColorRGBA(0.5f, 0.5f, 0.5f, 1));
//
//        DirectionalLight dr = new DirectionalLight();
//        dr.setEnabled(true);
//        dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
//        dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
//        dr.setDirection(new Vector3f(0.5f, -0.5f, 0));
//
//        CullState cs = renderer.createCullState();
//        cs.setCullFace(CullState.Face.Back);
//        cs.setEnabled(true);
//        rootNode.setRenderState(cs);
//
//        LightState lightState = renderer.createLightState();
//        lightState.setEnabled(true);
//        lightState.attach(dr);
//        rootNode.setRenderState(lightState);
//        lightState.setTwoSidedLighting(true);
//
//     terrainManager = new RandomTerrainManager("terrain");
//        //terrainManager = new HandMadeTerrain();
//
//        terrain = terrainManager.buildTerrain(rootNode);
//
//        sky = terrainManager.buildSky(rootNode, terrain);
//        rootNode.attachChild(terrain);
//
//
//
//    }
//  private void setupChaseCamera() {
//        Vector3f targetOffset = new Vector3f();
////        targetOffset.y = ((BoundingBox) player.getWorldBound()).yExtent * 15f;
//        HashMap props = new HashMap();
//        props.put(ThirdPersonMouseLook.PROP_MAXROLLOUT, "216");
//        props.put(ThirdPersonMouseLook.PROP_MINROLLOUT, "3");
//        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
//        props.put(ThirdPersonMouseLook.PROP_MAXASCENT, ""+180 * FastMath.DEG_TO_RAD);
//        props.put(ChaseCamera.PROP_INITIALSPHERECOORDS, new Vector3f(200, 0, 20 * FastMath.DEG_TO_RAD));
////        props.put(ChaseCamera.PROP_TARGETOFFSET, targetOffset);
//        chaser = new ChaseCamera(cam, player, props);
//        chaser.setMaxDistance(18);
//        chaser.setMinDistance(2);
//         this.renderer.setCamera(cam);
//    }
//
// /**
//     * create our custom input handler.
//     *
//     */
//    private void buildControllers() {
//        input = new InputHandler();
//        userActionController = new UserActionController(player, null, this.actionStates, input);
//        worldController = new ExternalWorldController(terrain);
//        interactionController = new InteractionController(actionStates, worldController);
//        collisionController = new CollisionController(this.actionStates);
//
//    }
//
//    private void buildFixedObjects() {
//
//
//        Box s1 = new Box("FixedBox2", new Vector3f(), 0.35f,0.25f,0.5f);
//        s1.setModelBound(new BoundingBox());
//        s1.updateModelBound();
//        s1.setLocalScale(3f);
//        fixedBox2 = new ObjectWithStates(new PlayerStateMachine(),"FixedBox2");
//        fixedBox2.setLocalTranslation(new Vector3f(100,0, 125));
//        rootNode.attachChild(fixedBox2);
//        fixedBox2.attachChild(s1);
//        fixedBox2.updateWorldBound();
//
//
//        float characterMinHeight = terrain.getHeight(fixedBox2.getLocalTranslation())
//                    +((BoundingBox)fixedBox2.getWorldBound()).yExtent;
//                if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
//                    fixedBox2.getLocalTranslation().y = characterMinHeight;
//                }
//
//        Box s = new Box("FixedBox", new Vector3f(), 0.35f,0.25f,0.5f);
//        s.setModelBound(new BoundingBox());
//        s.updateModelBound();
//        fixedBox = new ObjectWithStates(new PlayerStateMachine(),"FixedBox");
//        fixedBox.setLocalTranslation(new Vector3f(105,0, 125));
//        rootNode.attachChild(fixedBox);
//        fixedBox.attachChild(s);
//        fixedBox.updateWorldBound();
//
//            characterMinHeight = terrain.getHeight(fixedBox.getLocalTranslation())
//                    +((BoundingBox)fixedBox.getWorldBound()).yExtent;
//                if (!Float.isInfinite(characterMinHeight) && !Float.isNaN(characterMinHeight)) {
//                    fixedBox.getLocalTranslation().y = characterMinHeight;
//                }
//
//        actionStates.addObject(fixedBox);
//        actionStates.addObject(fixedBox2);
////        actionStates.getObjectsToValidateState().add(fixedBox);
////        actionStates.getObjectsToValidateState().add(fixedBox2);
//        }
//
//    public void setControllers(){
//        this.player.setColController(collisionController);
//    }
//
//
//
//    private void setupInput() {
//        this.buildControllers();
//        this.buildFixedObjects();
//
//        HashMap<String, Object> handlerProps = new HashMap<String, Object>();
//        handlerProps.put(ThirdPersonHandler.PROP_DOGRADUAL, "true");
//        handlerProps.put(ThirdPersonHandler.PROP_TURNSPEED, ""+(1.0f * FastMath.PI));
//        handlerProps.put(ThirdPersonHandler.PROP_LOCKBACKWARDS, "false");
//        handlerProps.put(ThirdPersonHandler.PROP_CAMERAALIGNEDMOVE, "true");
//        input = new ThirdPersonHandler(player, cam, handlerProps);
//        input.setActionSpeed(100f);
//
//
//    }
//}